import httpFetch from 'share/httpFetch';
import {message} from "antd";

const HotelReportServer = function (context) {
  return {
    // 基础信息
    async getReportBaseData(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post('/report/flight/queryHotelPriceReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false});
      }
    },
    // 表格详细数据
    async getReportDetailData(params, type){
      try {
        context.setState({loading: true});
        let url = type === 'm' ? '/report/flight/hotelMonthByMonthReport' : '/report/flight/hotelQuarterChartReport';
        const response = await httpFetch.post(url, params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false});
      }
    },
    // 星级分布
    async hotelStarDetailReport(params){
      try {
        context.setState({loading2: true});
        const response = await httpFetch.post('/report/flight/hotelStarDetailReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading2: false});
      }
    },
    // 酒店前5城市分析
    async hotelNightDetailReport(params){
      try {
        context.setState({loading3: true});
        const response = await httpFetch.post('/report/flight/hotelNightDetailReport', params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading3: false});
      }
    },
  }
}

const dealWithErrorMes = (err) => {
  message.error(`${err.response.data.message}`);
}

export default HotelReportServer;
